package logic

import (
	"context"
	"github.com/qiniu/x/errors"
	"house/model/mysql"

	"house/house"
	"house/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *house.UserListRequest) (*house.UserListResponse, error) {
	// todo: add your logic here and delete this line
	var u []mysql.User
	var userlist []*house.UserList
	mysql.DB.Find(&u)
	for _, s := range u {
		if s.Status != 1 && s.Status != 2 && s.Status != 3 {
			logx.Error("状态不正确")
			return nil, errors.New("状态不正确")
		}
		userlist = append(userlist, &house.UserList{
			Mobile:   s.Mobile,
			Password: s.Password,
		})
	}
	return &house.UserListResponse{
		List: userlist,
	}, nil
}
